<template>
  <div>
    <!-- Category商品分类 -->

    <el-button type="primary" size="medium" @click="openData">添加</el-button>

    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column fixed prop="id" label="ID"> </el-table-column>
      <el-table-column prop="name" label="分类名称"> </el-table-column>
      <el-table-column prop="level" label="顶级分类">
        <template slot-scope="scope">
          {{ scope.row.level === 1 ? "顶级分类" : "子分类" }}
        </template>
      </el-table-column>
      <el-table-column prop="wap_banner_url" label="图片">

        <template slot-scope="scope">
          <img :src="scope.row.wap_banner_url" alt="" style="height: 45px;" />
        </template>

      </el-table-column>
      <el-table-column prop="is_show" label="是否显示">
        <template slot-scope="scope">
          {{ scope.row.is_show && scope.row.is_show == 1 ? "是" : "否" }}
          <!--短路运算 && 前一个存在 就使用后一个数据 -->
        </template>
      </el-table-column>

      <el-table-column prop="sort_order" label="排序"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getCategoryApi } from "../../request/httpaip";
export default {
  data() {
    return {
      currentPage4: 1,
      //分页器当前页
      page: 1,
      //请求页数
      tableData: [],
      //表格数据
      pageSize: 10,
      //显示条数
      totalPages: 0,
      //总页数
      count: 0,
      //数据总数
    };
  },
  methods: {
    //一页显示条数事件
    handleSizeChange(val) {
      this.pagesize = val;
      // 获取商品属性接口
      getAttributeApi({
        page: this.page,
        size: this.pagesize,
        name: "",
      }).then((res) => {
        console.log(res.data);
        if (res.errno === 0) {
          this.tableData = res.data.data;
        }
      });
    },
    //页数点击事件
    handleCurrentChange(val) {
      this.page = val;

      // 获取商品属性接口
      getAttributeApi({
        page: this.page,
        size: this.pagesize,
        name: "",
      }).then((res) => {
        console.log(res.data);
        if (res.errno === 0) {
          this.tableData = res.data.data;
        }
      });
    },

    doFilter() {},
    // 跳转添加页事件
    openData() {
      this.$router.push({
        //核心语句
        path: "/addcategory", //跳转的路径
        query: {
          //路由传参时push和query搭配使用 ，作用时传递参数
          id: this.id,
        },
      });
    },
  },
  created() {
    getCategoryApi({}).then((res) => {
      console.log(res.data);
      if (res.errno === 0) {
        this.tableData = res.data;
      }
    });
  },
};
</script>
 
<style lang = "less" scoped>
/* 按钮样式  */
.el-button {
  margin-bottom: 8px;
}
</style>